package 作业2;

import java.util.Scanner;

public class SumOfDigit {

  // System.out.print("请输入数字: ");
  // int num = input.nextInt();
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);

    System.out.print("请输入一个整数：");
    int num = input.nextInt();

    if (num < 0) {
      System.out.println("请输入正整数。");
      return;
    }

    int sum = 0;

    while (num > 0) {
      int digit = num % 10;
      sum += digit;
      num /= 10;
    }

    System.out.println("各位数字之和为："+sum);
  }
}
